<!DOCTYPE html>
<html>
<head>
    <title>修改医生--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../layer/layer.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>
 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
</head>
<body>
<form action="#" id="myForm" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td><input type="hidden" name="d_id" value="1001"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">姓名</td>
        <td><input type="text" name="d_name" onclick="checkName()" value="程俊"/></td>
    </tr>
    
    <tr>
        <td width="10%" class="tableleft">身份证号</td>
        <td><input type="text" name="d_idCar" onclick="checkCar()" value=""/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">手机</td>
        <td><input type="text" name="d_phone" onclick="checkPhone()" value="15343457897"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">座机</td>
        <td><input type="text" name="d_telPhone" onclick="checkTelPhone()" value="01088586875"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">性别</td>
        <td><input type="radio" name="d_sex" value="1" checked/>男&nbsp;&nbsp;&nbsp;<input type="radio" name="d_sex" value="0"/>女</td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">出生年月</td>
        <td><input type="text" name="d_birthday" onclick="checkBirthday()" value="1986-09-06"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">年龄</td>
        <td><input type="text" name="d_age" onclick="checkAge()" value="18"></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">电子邮箱</td>
        <td><input type="text" name="d_email" onclick="checkEmail()" value="chengjun@msn.com.cn"/></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">所属科室</td>
        <td><select id="doc1" name="d_keshi"><option value="急诊科">急诊科</option><option value="骨科">骨科</option><option value="血液科">血液科</option >
            <option value="妇科">妇科</option><option value="牙科">牙科</option><option value="内科">内科</option><option value="外科">外科</option></select></td>
    </tr>
    <tr>
        <td width="10%" class="tableleft">学历</td>
        <td><select id="doc2" name="d_xueli"><option value="专科">专科</option><option value="本科">本科</option><option value="博士">博士</option><option value="博士后">博士后</option>
            <option value="硕士">硕士</option><option value="研究生">研究生</option></select></td>
    </tr>
	<tr>
        <td width="10%" class="tableleft">备注</td>
        <td><textarea id="d_desc" name="d_desc">此人表现优异工作非常的积极！</textarea></td>
	</tr>
    <tr>
        <td colspan="2">
			<center>
				<button class="btn btn-primary" type="button" id="btn">保存</button> &nbsp;&nbsp;<button type="button" class="btn btn-success" name="backid" id="backId">返回列表</button>
			</center>
		</td>
    </tr>
</table>
</form>
</body>
</html>
<script type="text/javascript">
    String.prototype.GetValue= function(para) {
        let reg = new RegExp("(^|&)"+ para +"=([^&]*)(&|$)");
        let r = this.substr(this.indexOf("\?")+1).match(reg);
        if (r!=null) return unescape(r[2]); return null;
    }
    $(function () {
        //根据地址获取teamId,如果null则执行增加，否则执行更新
        let url = document.location.toString();//获取URL
        let d_id = url.GetValue("d_id");
        let pageNum = url.GetValue("pageNum");
        load(d_id);
        $('#backId').click(function(){
            window.location.href="index.html?pageNum="+pageNum;
        });
        $('#btn').click(function(){
            upload(pageNum);
        });
    });

    function load(d_id){
        let windowId = layer.load();
        $.ajax({
            type: "GET",
            url: "/doctor/queryById/"+d_id, //RESTful风格的API定义
            data: "",
            dataType:"json",
            success: function (vo) {
                layer.close(windowId);
                if (vo.code == 200){
                    let obj=vo.obj;
                    let d_id=obj.d_id;
                    let d_name=obj.d_name==null?'数据丢失':obj.d_name;
                    let d_idCar=obj.d_idCar==null?'数据丢失':obj.d_idCar;
                    let d_telPhone=obj.d_telPhone==null?'数据丢失':obj.d_telPhone;
                    let d_phone=obj.d_phone==null?'数据丢失':obj.d_phone;
                    let d_sex=obj.d_sex;
                    let d_age=obj.d_age;
                    let d_birthday=obj.d_birthday==null?'数据丢失':obj.d_birthday;
                    let d_email=obj.d_email==null?'数据丢失':obj.d_email;
                    let d_desc=obj.d_desc==null?'数据丢失':obj.d_desc;
                    let d_keshi=obj.d_keshi==null?'数据丢失':obj.d_keshi;
                    let d_xueli=obj.d_xueli==null?'数据丢失':obj.d_xueli;
                    $("input[name='d_id']").val(d_id);
                    $("input[name='d_name']").val(d_name);
                    $("input[name='d_idCar']").val(d_idCar);
                    $("input[name='d_phone']").val(d_phone);
                    $("input[name='d_telPhone']").val(d_telPhone);
                    $("input[name='d_age']").val(d_age);
                    $("input[name='d_birthday']").val(d_birthday);
                    $("input[name='d_email']").val(d_email);
                    $("#d_desc").html(d_desc);
                    if (d_sex=='0'){
                        $("input[name='d_sex']")[1].checked='checked';
                    }else {
                        $("input[name='d_sex']")[0].checked='checked';
                    }
                    let doc1 = document.getElementById("doc1");
                    for (let i = 0;i < doc1.options.length;i++){
                        if (doc1.options[i].value == d_keshi){
                            doc1.options[i].selected =' selected ';
                            break;
                        }
                    }
                    let doc2 = document.getElementById("doc2");
                    for (let i = 0;i < doc2.options.length;i++){
                        if (doc2.options[i].value == d_xueli){
                            doc2.options[i].selected =' selected ';
                            break;
                        }
                    }
                }else {
                    layer.msg(vo.msg);
                }
            }
        });
    }

    function upload(pageNum){
        let windowId = layer.load();
        $.ajax({
            type: "POST",
            url: "/doctor/update",
            data: $("#myForm").serialize()+"&_method=PUT",
            dataType: "json",
            success: function (vo) {
                layer.close(windowId);
                alert(vo.msg);
                if (vo.code == 200){
                    window.location.href="index.html?pageNum="+pageNum;
                }
            }
        });
    }
    function checkName(){
        layer.tips("请输入2-4位有效名字","input:eq(1)",{tipsMore:true,tips:2});
    }
    function checkCar(){
        layer.tips("请输入18位有效身份证号","input:eq(2)",{tipsMore:true,tips:2});
    }
    function checkTelPhone(){
        layer.tips("请输入6位有效电话号","input:eq(4)",{tipsMore:true,tips:2});
    }
    function checkPhone(){
        layer.tips("请输入11位有效手机号","input:eq(3)",{tipsMore:true,tips:2});
    }
    function checkBirthday(){
        layer.tips("请输入有效日期，2021-07-14","input:eq(7)",{tipsMore:true,tips:2});
    }
    function checkAge(){
        layer.tips("请输入0-99有效年龄","input:eq(8)",{tipsMore:true,tips:2});
    }
    function checkEmail(){
        layer.tips("请输入正确邮箱xx@qq.com","input:eq(9)",{tipsMore:true,tips:2});
    }
</script>